/*************************************************
Do File description: This do file brings in the Michigan data
 and runs all of the tables and figures for 
 "College Counseling in the Classroom: Randomized Evaluation
 of a Teacher-Based Approach to College Advising" in JOLE.

Created by: Josh Hyman
Date: 12/17/2024

*************************************************/

# delimit;
clear;
clear matrix;
clear mata;
set maxvar 20000;
set mem 7500m;
set matsize 3000;
set more off;
capture log close;
program drop _all;
macro drop _all;

estimates clear;

*CREATE LOG FILE;
log using XXXXXX.log, replace; 

*BRING IN MICHIGAN K-12 DATA;
use student_level_data, clear;

*CREATE OTHER RACE CATEGORY;
gen oth_race = inlist(racecat,1,2,4);

*CREATE URBANICITY CATEGORIES;
drop city suburb rural;
gen city = urbanicity==1;
gen suburb = urbanicity==2;
gen town = urbanicity==3;
gen rural = urbanicity==4;

*CREATE DUMMY FOR HAS 8TH GRADE TEST SCORE;
gen has_gr8_score = mathread_gr8~=.;

*CREATE FRACTION POOR AND BLACK USING EPI DATA;
gen frac_poor = n_povertyflag_2017/n_school_2017;
gen frac_black = n_black_2017/n_school_2017;

*CREATE FRACTION ATTEND COLLEGE;
egen temp1 = total(enr_fall_any_2016) if year==2016, by(bcode);
egen temp2 = total(enr_fall_4yr_2016) if year==2016, by(bcode);
egen temp3 = max(temp1), by(bcode);
egen temp4 = max(temp2), by(bcode);

gen frac_enr = temp3 / n_gr12_2016;
gen frac_enr_4yr = temp4 / n_gr12_2016;

*MERGE IN MORE NSC POSTSECONDARY DATA;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2017) ukeep(fall enr4yr_pub_inst_fall enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2017_);
drop if _merge==2;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2018) 
	ukeep(spring enr4yr_pub_inst_spring enr2yr_pub_inst_spring enr4yr_pub_outst_spring two_yr_spring enr4yr_priv_inst_spring enr4yr_priv_outst_spring fall enr4yr_pub_inst_fall enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2018_);
drop if _merge==2;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2019) ukeep(spring enr4yr_pub_inst_spring enr2yr_pub_inst_spring enr4yr_pub_outst_spring two_yr_spring enr4yr_priv_inst_spring enr4yr_priv_outst_spring fall enr4yr_pub_inst_fall  enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2019_);
drop if _merge==2;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2020) ukeep(spring enr4yr_pub_inst_spring enr2yr_pub_inst_spring enr4yr_pub_outst_spring two_yr_spring enr4yr_priv_inst_spring enr4yr_priv_outst_spring fall enr4yr_pub_inst_fall enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2020_);
drop if _merge==2;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2021) ukeep(spring enr4yr_pub_inst_spring enr2yr_pub_inst_spring enr4yr_pub_outst_spring two_yr_spring enr4yr_priv_inst_spring enr4yr_priv_outst_spring fall enr4yr_pub_inst_fall enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2021_);
drop if _merge==2;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2022) ukeep(spring enr4yr_pub_inst_spring enr2yr_pub_inst_spring enr4yr_pub_outst_spring two_yr_spring enr4yr_priv_inst_spring enr4yr_priv_outst_spring fall enr4yr_pub_inst_fall enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2022_);
drop if _merge==2;
mmerge ric using nsc_clean_student_x_year_level, t(n:1) uif(year==2023) ukeep(spring enr4yr_pub_inst_spring enr2yr_pub_inst_spring enr4yr_pub_outst_spring two_yr_spring enr4yr_priv_inst_spring enr4yr_priv_outst_spring fall enr4yr_pub_inst_fall enr2yr_pub_inst_fall enr4yr_pub_outst_fall two_yr_fall enr4yr_priv_inst_fall enr4yr_priv_outst_fall) uname(y2023_);
drop if _merge==2;


*BRING IN OPEIDS AND DEGREE FROM STUDENT-LEVEL NSC;
mmerge ric using nsc_clean_student_level, t(n:1) 
	ukeep(barrons1 barrons2 barrons3 barrons4 opeid_code1 opeid_code2 opeid_code3 opeid_code4 four_yr1 four_yr2 four_yr3 four_yr4 grad_date1_1 grad_date1_2 grad_date1_3 grad_date1_4 ever_degree
	sems_any_ttl sems_ft_ttl sems_ltft_ttl sems_miss_ttl yrs_cred1 yrs_cred2 yrs_cred3
	ever_prv ever_outstate);
drop if _merge==2;

foreach x in ever_degree sems_any_ttl sems_ft_ttl sems_ltft_ttl sems_miss_ttl yrs_cred1 yrs_cred2 yrs_cred3 ever_prv ever_outstat {;
	replace `x' = 0 if _merge==1;
};
	
*CREATE DUMMY FOR UNDERMATCH;
forvalues i=1/4 {;
     gen byte enr_safety_`i' = 1 if (four_yr`i'==0 | act75th`i'==. | sat_score_act_scale>=act75th`i') & four_yr`i'~=.;
     gen byte enr_reach_`i' = 1 if four_yr`i'==1 & act75th`i'~=. & sat_score_act_scale<=act25th`i';
     gen byte enr_match_`i' = 1 if four_yr`i'==1 & act75th`i'~=. & sat_score_act_scale>act25th`i' & sat_score_act_scale<act75th`i';
};

*CREATE BETTER MEAUSURES OF SELECTIVE COLLEGE ENROLLMENT;
forvalues i=1/4 {;
    gen enr_vsel_`i' = inlist(barrons`i',5,6);
	gen enr_4yr_hACT25_`i' = 1 if four_yr`i'==1 & act25th`i'>=20 & act25th`i'~=.;
	gen enr_4yr_lACT25_`i' = 1 if four_yr`i'==1 & act25th`i'<=19;
	gen enr_4yr_hACT75_`i' = 1 if four_yr`i'==1 & act75th`i'>=26 & act75th`i'~=.;
	gen enr_4yr_lACT75_`i' = 1 if four_yr`i'==1 & act75th`i'<=25;
};

foreach x in vsel 4yr_hACT25 4yr_lACT25 4yr_hACT75 4yr_lACT75 safety reach match {; 
	capture drop enr_`x';
	gen enr_`x' = 0;
	forvalues y=1/4 {;
		replace enr_`x' = 1 if enr_`x'_`y'==1;
	};
};

*BRING IN STUDENT-LEVEL STARR GPA AND CREDITS DATA;
mmerge ric using STARR, t(n:1);
drop if _merge==2;
replace creds_fnl = 0 if creds_fnl==.;
	
*CREATE VARS FOR ENROLLED IN 2018, 2019, 2020, 2021 (spring) school year;
gen enrolled_2018 = y2017_fall==1 | y2018_spring==1;
gen enrolled_2019 = y2018_fall==1 | y2019_spring==1;
gen enrolled_2020 = y2019_fall==1 | y2020_spring==1;
gen enrolled_2021 = y2020_fall==1 | y2021_spring==1;
gen enrolled_2022 = y2021_fall==1 | y2022_spring==1;
gen enrolled_2023 = y2022_fall==1 | y2023_spring==1;

gen enr_ever = inlist(1,enrolled_2018,enrolled_2019,enrolled_2020,enrolled_2021);

*CREATE VARS FOR ENROLLED WITHIN 2 YEARS AND PERSISTS TO YEARS 2, 3, 4;
gen enr_w_2yr = enrolled_2018==1 | enrolled_2019==1;
gen enr_w_2yr_p2 = (enrolled_2018==1 & enrolled_2019==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2020==1);
gen enr_w_2yr_p3 = (enrolled_2018==1 & enrolled_2020==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2021==1);
gen enr_w_2yr_p4 = (enrolled_2018==1 & enrolled_2021==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2022==1);

gen enr_w_2yr_p3c = (enrolled_2018==1 & enrolled_2019==1 & enrolled_2020==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2020==1 & enrolled_2021==1);
gen enr_w_2yr_p4c = (enrolled_2018==1 & enrolled_2019==1 & enrolled_2020==1 & enrolled_2021==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2020==1 & enrolled_2021==1 & enrolled_2022==1);

gen enr_everp2 = (enrolled_2018==1 & enrolled_2019==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2020==1) | 
	(enrolled_2018~=1 & enrolled_2019~=1 & enrolled_2020==1 & enrolled_2021==1) | 
	(enrolled_2018~=1 & enrolled_2019~=1 & enrolled_2020~=1 & enrolled_2021==1 & enrolled_2022==1) | 
	(enrolled_2018~=1 & enrolled_2019~=1 & enrolled_2020~=1 & enrolled_2021~=1 & enrolled_2022==1 & enrolled_2023==1);

gen enr_everp3 = (enrolled_2018==1 & enrolled_2020==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2021==1) | 
	(enrolled_2018~=1 & enrolled_2019~=1 & enrolled_2020==1 & enrolled_2022==1) |
 	(enrolled_2018~=1 & enrolled_2019~=1 & enrolled_2020~=1 & enrolled_2021==1 & enrolled_2023==1);

gen enr_everp4 = (enrolled_2018==1 & enrolled_2021==1) | (enrolled_2018~=1 & enrolled_2019==1 & enrolled_2022==1);

*CREATE enrollment in and continous enrollment through years n, n+1, n+2, n+3;
*NOTE - enrollment in years 1, 2, 3, 4 are just enrolled_2018, enrolled_2019, enrolled_2020, enrolled_2021;
*CONTINOUS ENROLLMENT THROUGH YEAR 2;
gen cont_enr_np1 = enrolled_2018==1 & enrolled_2019==1;
gen cont_enr_np2 = enrolled_2018==1 & enrolled_2019==1 & enrolled_2020==1;
gen cont_enr_np3 = enrolled_2018==1 & enrolled_2019==1 & enrolled_2020==1 & enrolled_2021==1;

gen enr_ever_s2 = 
	(y2017_fall==1 & y2018_spring==1) 
	| (y2017_fall~=1 & y2018_spring==1 & y2018_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall==1 & y2019_spring==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring==1 & y2019_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall==1 & y2020_spring==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring==1 & y2020_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall==1 & y2021_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall~=1 & y2021_spring==1 & 		
		y2021_fall==1);		
	
gen enr_ever_s3 = 
	(y2017_fall==1 & y2018_fall==1) 
	| (y2017_fall~=1 & y2018_spring==1 & y2019_spring==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall==1 & y2019_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring==1 & y2020_spring==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall==1 & y2020_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring==1 & y2021_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall==1 & y2021_fall==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall~=1 & 
		y2021_spring==1 & y2022_spring==1);

gen enr_ever_s4 = 
	(y2017_fall==1 & y2019_spring==1) 
	| (y2017_fall~=1 & y2018_spring==1 & y2019_fall==1)  
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall==1 & y2020_spring==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring==1 & y2020_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall==1 & y2021_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring==1 & y2021_fall==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall==1 & y2022_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall~=1 & y2021_spring==1 
		& y2022_fall==1);

gen enr_ever_s5 = 
	(y2017_fall==1 & y2019_fall==1) 
	| (y2017_fall~=1 & y2018_spring==1 & y2020_spring==1)  
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall==1 & y2020_fall==1) 
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring==1 & y2021_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall==1 & y2021_fall==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring==1 & y2022_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall==1 & y2022_fall==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring~=1 & y2020_fall~=1 & y2021_spring==1 
		& y2023_spring==1); 

gen enr_ever_s6 = 
	(y2017_fall==1 & y2020_spring==1) 
	| (y2017_fall~=1 & y2018_spring==1 & y2020_fall==1)  
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall==1 & y2021_spring==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring==1 & y2021_fall==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall==1 & y2022_fall==1)
	| (y2017_fall~=1 & y2018_spring~=1 & y2018_fall~=1 & y2019_spring~=1 & y2019_fall~=1 & y2020_spring==1 & y2023_spring==1);
	
drop temp1;	
egen temp1 = rowtotal(y2017_fall y2018_spring y2018_fall y2019_spring y2019_fall y2020_spring y2020_fall y2021_spring);
gen num_sems = temp1;
drop temp1;


*CREATE VARS FOR ENROLLED WITHIN 2 YEARS IN A 4-YEAR PUBLIC, 4-YEAR PRIVATE, 2-YEAR (could also do 4-year public in-state vs in-state private AND out-state public);

gen enr_4pub = inlist(1, 
	y2017_enr4yr_pub_inst_fall,
	y2017_enr4yr_pub_outst_fall,
	y2018_enr4yr_pub_inst_spring,
	y2018_enr4yr_pub_outst_spring,
	y2018_enr4yr_pub_inst_fall,
	y2018_enr4yr_pub_outst_fall,
	y2019_enr4yr_pub_inst_spring,
	y2019_enr4yr_pub_outst_spring,
	y2019_enr4yr_pub_inst_fall,
	y2019_enr4yr_pub_outst_fall,
	y2020_enr4yr_pub_inst_spring,
	y2020_enr4yr_pub_outst_spring,
	y2020_enr4yr_pub_inst_fall,
	y2020_enr4yr_pub_outst_fall,
	y2021_enr4yr_pub_inst_spring,
	y2021_enr4yr_pub_outst_spring);

gen enr_4prv = inlist(1, 
	y2017_enr4yr_priv_inst_fall,
	y2017_enr4yr_priv_outst_fall,
	y2018_enr4yr_priv_inst_spring,
	y2018_enr4yr_priv_outst_spring,
	y2018_enr4yr_priv_inst_fall,
	y2018_enr4yr_priv_outst_fall,
	y2019_enr4yr_priv_inst_spring,
	y2019_enr4yr_priv_outst_spring,
	y2019_enr4yr_priv_inst_fall,
	y2019_enr4yr_priv_outst_fall,
	y2020_enr4yr_priv_inst_spring,
	y2020_enr4yr_priv_outst_spring,
	y2020_enr4yr_priv_inst_fall,
	y2020_enr4yr_priv_outst_fall,
	y2021_enr4yr_priv_inst_spring,
	y2021_enr4yr_priv_outst_spring);

drop enr_2yr;	
gen enr_2yr = inlist(1,
	y2017_two_yr_fall,
	y2018_two_yr_spring,
	y2018_two_yr_fall,
	y2019_two_yr_spring,
	y2019_two_yr_fall,
	y2020_two_yr_spring,
	y2020_two_yr_fall,
	y2021_two_yr_spring);

drop enr_4yr;
gen enr_4yr = enr_4pub | enr_4prv;
gen enr_4only = enr_4yr==1 & enr_2yr==0;
gen enr_2only = enr_4yr==0 & enr_2yr==1;
gen enr_2and4 = enr_4yr==1 & enr_2yr==1;


*CREATE VAR FOR EVER ENROLLED IN AN INSTATE-PUBLIC;
gen enr_ever_instate_pub = 
	inlist(1,y2017_enr4yr_pub_inst_fall,y2017_enr2yr_pub_inst_fall,
	y2018_enr4yr_pub_inst_spring,y2018_enr2yr_pub_inst_spring,
	y2018_enr4yr_pub_inst_fall,y2018_enr2yr_pub_inst_fall,
	y2019_enr4yr_pub_inst_spring,y2019_enr2yr_pub_inst_spring,
	y2019_enr4yr_pub_inst_fall,y2019_enr2yr_pub_inst_fall,
	y2020_enr4yr_pub_inst_spring,y2020_enr2yr_pub_inst_spring,
	y2020_enr4yr_pub_inst_fall,y2020_enr2yr_pub_inst_fall,
	y2021_enr4yr_pub_inst_spring,y2021_enr2yr_pub_inst_spring);



gen enr_4yr_2017_fall = inlist(1,y2017_enr4yr_pub_inst_fall,y2017_enr4yr_pub_outst_fall,y2017_enr4yr_priv_inst_fall,y2017_enr4yr_priv_outst_fall);
foreach x in 2018 2019 2020 {;
	gen enr_4yr_`x'_fall = inlist(1,y`x'_enr4yr_pub_inst_fall,y`x'_enr4yr_pub_outst_fall,y`x'_enr4yr_priv_inst_fall,y`x'_enr4yr_priv_outst_fall);
	gen enr_4yr_`x'_spring = inlist(1,y`x'_enr4yr_pub_inst_spring,y`x'_enr4yr_pub_outst_spring,y`x'_enr4yr_priv_inst_spring,y`x'_enr4yr_priv_outst_spring);
};
gen enr_4yr_2021_spring = inlist(1,y2021_enr4yr_pub_inst_spring,y2021_enr4yr_pub_outst_spring,y2021_enr4yr_priv_inst_spring,y2021_enr4yr_priv_outst_spring);

gen first_2yr = enr_2and4==1 & (
	(y2017_two_yr_fall==1 & enr_4yr_2017_fall==0) |
	(y2018_two_yr_spring==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0) |
	(y2018_two_yr_fall==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0 & enr_4yr_2018_fall==0) | 
	(y2019_two_yr_spring==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0 & enr_4yr_2018_fall==0 & enr_4yr_2019_spring==0) |
	(y2019_two_yr_fall==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0 & enr_4yr_2018_fall==0 & enr_4yr_2019_spring==0 & enr_4yr_2019_fall==0) |
	(y2020_two_yr_spring==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0 & enr_4yr_2018_fall==0 & enr_4yr_2019_spring==0 & enr_4yr_2019_fall==0 & 		enr_4yr_2020_spring==0) |
	(y2020_two_yr_fall==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0 & enr_4yr_2018_fall==0 & enr_4yr_2019_spring==0 & enr_4yr_2019_fall==0 & 		
		enr_4yr_2020_spring==0 & enr_4yr_2020_fall==0) |
	(y2021_two_yr_spring==1 & enr_4yr_2017_fall==0 & enr_4yr_2018_spring==0 & enr_4yr_2018_fall==0 & enr_4yr_2019_spring==0 & enr_4yr_2019_fall==0 & 		enr_4yr_2020_spring==0 & enr_4yr_2020_fall==0 & enr_4yr_2021_spring==0)	
	);
gen first_4yr = enr_2and4==1 & (
	(enr_4yr_2017_fall==1 & y2017_two_yr_fall==0) |
	(enr_4yr_2018_spring==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0) |
	(enr_4yr_2018_fall==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0 & y2018_two_yr_fall==0) | 
	(enr_4yr_2019_spring==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0 & y2018_two_yr_fall==0 & y2019_two_yr_spring==0) |
	(enr_4yr_2019_fall==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0 & y2018_two_yr_fall==0 & y2019_two_yr_spring==0 & y2019_two_yr_fall==0) |
	(enr_4yr_2020_spring==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0 & y2018_two_yr_fall==0 & y2019_two_yr_spring==0 & y2019_two_yr_fall==0 & 		y2020_two_yr_spring==0) |
	(enr_4yr_2020_fall==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0 & y2018_two_yr_fall==0 & y2019_two_yr_spring==0 & y2019_two_yr_fall==0 & 		y2020_two_yr_spring==0 & y2020_two_yr_fall==0) |
	(enr_4yr_2021_spring==1 & y2017_two_yr_fall==0 & y2018_two_yr_spring==0 & y2018_two_yr_fall==0 & y2019_two_yr_spring==0 & y2019_two_yr_fall==0 & 		y2020_two_yr_spring==0 & y2020_two_yr_fall==0 & y2021_two_yr_spring==0)	
	);	
gen enr_2_4_simal = enr_2and4==1 & first_2yr==0 & first_4yr==0;

*GEN 2-YEAR DEGREE;
gen degree_2yr = (four_yr1==0 & grad_date1_1~=.) | (four_yr2==0 & grad_date1_2~=.) | (four_yr3==0 & grad_date1_3~=.) | (four_yr3==0 & grad_date1_3~=.);

*GEN 4-YEAR DEGREE;
gen degree_4yr = (four_yr1==1 & grad_date1_1~=.) | (four_yr2==1 & grad_date1_2~=.) | (four_yr3==1 & grad_date1_3~=.) | (four_yr3==1 & grad_date1_3~=.);

gen degree_2_and_4 = degree_2yr==1 & degree_4yr==1;
gen degree_2yr_o = degree_2yr==1 & degree_4yr==0;
gen degree_4yr_o = degree_4yr==1 & degree_2yr==0;
gen degree_2_or_4 = degree_2yr==1 | degree_4yr==1;

*CREATE BINARY GPA AND CREDITS EARNED VARIABLES - note that gpa_fnl is STARR and gpa_baseline is high school;
gen enr_gpagt2 = enr_ever==1 & gpa_fnl>=2 & gpa_fnl~=.;
gen enr_gpalt2 = enr_ever==1 & gpa_fnl<2 & gpa_fnl~=.;

gen enr_gpagt3 = enr_ever==1 & gpa_fnl>=3 & gpa_fnl~=.;
gen enr_gpa173 = enr_ever==1 & gpa_fnl>=1.7  & gpa_fnl<3 & gpa_fnl~=.;
gen enr_gpalt17 = enr_ever==1 & gpa_fnl<1.7 & gpa_fnl~=.;

*FIND MEDIAN GPA FOR CONTROL GROUP;
sum gpa_fnl if enr_ever==1 & year==2017==1 & treat==0 & gpa_fnl~=.,d;

gen coll_gpa = gpa_fnl;
replace coll_gpa=. if enr_ever==0;

gen enr_gpa_hi = enr_ever==1 & gpa_fnl>=2.545455 & gpa_fnl~=.;
gen enr_gpa_lo = enr_ever==1 & gpa_fnl<2.545455  & gpa_fnl~=.;


*CREATE TABLE 1 RCT SAMPLE SUM STATS;
gen urb_sub = city==1 | suburb==1;
gen town_rrl = town==1 | rural==1;

local sumvars female povertyflag white black hisp oth_race city suburb town rural urb_sub town_rrl charter n_gr12_2017 sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt;
tabstat `sumvars' if year==2017, stat(mean n) col(stat);
tabstat `sumvars' if year==2017 & treat==1, stat(mean n) col(stat);
tabstat `sumvars' if year==2017 & treat==0, stat(mean n) col(stat);

tabstat enr_fall_any_2016 enr_fall_4yr_2016 if year==2016,stat(mean n) col(stat);
tabstat enr_fall_any_2016 enr_fall_4yr_2016 if year==2016 & treat==1,stat(mean n) col(stat);
tabstat enr_fall_any_2016 enr_fall_4yr_2016 if year==2016 & treat==0,stat(mean n) col(stat);

tabstat ba_degree if year==2011,stat(mean n) col(stat);
tabstat ba_degree if year==2011 & treat==1,stat(mean n) col(stat);
tabstat ba_degree if year==2011 & treat==0,stat(mean n) col(stat);

***CREATE APPENDIX TABLE 1;
egen tag = tag(bcode);
sum frac_treated if treat==1 & tag==1, d;

foreach x in female povertyflag white black hisp oth_race sat_composite gpa_baseline attendance_rt {;
	egen tmp_`x' = mean(`x') if year==2017, by(bcode);
	egen schl_`x' = max(tmp_`x'), by(bcode);
};

local sumvars2 schl_povertyflag schl_white schl_black schl_hisp schl_oth_race schl_sat_composite schl_gpa_baseline city suburb town rural charter n_gr12_2017;

tabstat `sumvars2' if tag==1 & treat==1 & frac_treated<.5024876, stat(mean n) col(stat);
tabstat `sumvars2' if tag==1 & treat==1 & frac_treated>=.5024876 & frac_treated<.6413793, stat(mean n) col(stat);
tabstat `sumvars2' if tag==1 & treat==1 & frac_treated>=.6413793 & frac_treated<.8490566, stat(mean n) col(stat);
tabstat `sumvars2' if tag==1 & treat==1 & frac_treated>=.8490566, stat(mean n) col(stat);

count if year==2017 & treat==1 & frac_treated<.5024876;
count if year==2017 & treat==1 & frac_treated>=.5024876 & frac_treated<.6413793;
count if year==2017 & treat==1 & frac_treated>=.6413793 & frac_treated<.8490566;
count if year==2017 & treat==1 & frac_treated>=.8490566;

foreach y in `sumvars2' {;
	reg frac_treated `y' if tag==1 & treat==1, vce(robust); 
};
*****




***DO TABLE 1 BALANCE RESULTS REGRESSIONS**;

*CREATE BLOCK DUMMIES;
tab block, gen(block_);

*FOR EACH BALANCE VARIABLE;
foreach x in female povertyflag white black hisp oth_race city suburb town rural urb_sub town_rrl charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt {;

	*CONTROLLING FOR BLOCKS;
	reg `x' treat block_* 
		female povertyflag black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
		if year==2017, vce(cluster bcode);
	estimates store `x'_2;
};
*/
};
	
estout female_*  
       using tab1_balance.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(N, fmt(0) labels("Observations")) 
       keep(treat);

foreach x in povertyflag white black hisp oth_race city suburb town rural /*urb_sub town_rrl */ charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt {;
	estout `x'_*
       	       using tab1_balance.txt", append
       	       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(N, fmt(0) labels("Observations"))
       	       keep(treat);
};



gen male = female==0;
gen nonwhite = white==0;
gen nonpoor = povertyflag==0;
gen all = 1;
rename povertyflag poor;
gen higpa = gpa_baseline>=2.592857;
gen logpa = gpa_baseline<2.592857 & gpa_baseline~=0;
gen hisat = sat_composite>=900;
gen losat = sat_composite<900 & sat_composite~=0;

gen vlgs = logpa==1 & losat==1;
gen migs = vlgs~=1;
gen logs = logpa==1 | losat==1;
gen higs = logs~=1;
gen pr_hig = poor==1 & higpa==1;
gen pr_log = poor==1 & logpa==1;
gen pr_his = poor==1 & hisat==1;
gen pr_los = poor==1 & losat==1;
gen pr_hie = poor==1 & higs==1;
gen pr_loe = poor==1 & logs==1;
gen np_hie = nonpoor==1 & higs==1;
gen np_loe = nonpoor==1 & logs==1;

gen pr_hie2 = poor==1 & migs==1;
gen pr_loe2 = poor==1 & vlgs==1;
gen np_hie2 = nonpoor==1 & migs==1;
gen np_loe2 = nonpoor==1 & vlgs==1;

gen fm_hie = female==1 & higs==1;
gen fm_loe = female==1 & logs==1;
gen ml_hie = male==1 & higs==1;
gen ml_loe = male==1 & logs==1;

gen wh_hie = white==1 & higs==1;
gen wh_loe = white==1 & logs==1;
gen bl_hie = black==1 & higs==1;
gen bl_loe = black==1 & logs==1;

gen minority = black==1 | hisp==1;

gen mn_hie = minority==1 & higs==1;
gen mn_loe = minority==1 & logs==1;
gen nw_hie = nonwhite==1 & higs==1;
gen nw_loe = nonwhite==1 & logs==1;

*SET MISSING CONTROLS TO ZERO AND CREATE MISSING DUMMIES;
foreach x in sat_composite mathread_gr8 gpa_baseline attendance_rt {;
	gen `x'_miss = `x'==.;
	replace `x' = 0 if `x'_miss==1;
};


*APPENDIX TABLE 2;
egen tmp_higs = mean(higs) if year==2017, by(bcode);
egen schl_higs = max(tmp_higs), by(bcode);

sum schl_povertyflag schl_higs if tag==1,d;

*CREATE DUMMY FOR HIGH-SHARE AND LOW-SHARE ED SCHOOLS to examine hetero effects later;
gen hs_schl_pov = schl_povertyflag>=0.4852826;
gen ls_schl_pov = hs_schl_pov==0;
gen pr_hp = poor==1 & hs_schl_pov==1;
gen np_hp = nonpoor==1 & hs_schl_pov==1;
gen pr_lp = poor==1 & hs_schl_pov==0;
gen np_lp = nonpoor==1 & hs_schl_pov==0;

gen hs_schl_higs = schl_higs>=.4456569;


gen apply_any = .;
replace apply_any = 1 if apply_4yr==1 | apply_2yr==1;
replace apply_any = 0 if apply_any==. & (apply_4yr~=. | apply_2yr~=.);


*CHECK OUT PRIVATE AND OUT-OF-STATE ENROLLMENT FOR SUBGROUPS;
gen ever_prv_out = ever_prv==1 | ever_outstate==1;
foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie {;
	di "`x'";
	sum ever_prv_out ever_prv ever_outstate if `x'==1 & year==2017 & treat==0;
};


foreach x in ever_ba ever_aa only_aa only_ba ever_any {;
	replace `x'=0 if `x'==.;
};
	
gen ever_ba_and_aa = ever_ba==1 & ever_aa==1;

forvalues x=2/8 {;
	gen sems`x' = sems_any_ttl>=`x';
};

gen enr_ever_p2s = sems3==1; 
gen enr_ever_p3s = sems5==1;
gen enr_ever_p4s = sems7==1;

gen enr_ever_p2t = sems4==1; 
gen enr_ever_p3t = sems6==1;
gen enr_ever_p4t = sems8==1;


*CREATE COLLEGE MATCH VARIABLES;
gen enr_hi_act = enr_4yr_hACT25 | enr_4yr_hACT75;
gen enr_s_only = enr_safety==1 & enr_match==0 & enr_reach==0;
gen enr_s_and_r = enr_safety==1 & enr_reach==1;
gen enr_s_and_mr = enr_safety==1 & (enr_match==1 | enr_reach==1);
gen enr_s_and_m = enr_safety==1 & enr_match==1;
gen enr_m_or_r = enr_match==1 | enr_reach==1;

*CREATE ENROLLMENT INTENSITY VARIABLES;
drop enr_ft;
gen enr_ft = sems_ft_ttl>0 & sems_ft_ttl~=.;
gen enr_pt_only = sems_ltft_ttl>0 & sems_ltft_ttl~=. & (sems_ft_ttl==0 | sems_ft_ttl==.);
gen enr_ft_only = sems_ft_ttl>0 & sems_ft_ttl~=. & (sems_ltft_ttl==0 | sems_ltft_ttl==.);
gen enr_pt = sems_ltft_ttl>0 & sems_ltft_ttl~=.;
gen enr_pt_ft = enr_ft & enr_pt;


*EFFECTS ON POSTSECONDARY ENROLLMENT - Table 2, 3, 4, 5;
estimates clear;
foreach y in enr_ever enr_everp2 enr_everp3 enr_everp4 ever_any ever_aa ever_ba {;

	foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie {; 

		*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};

estout t_enr_ever_*
       using tabs2345.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);
foreach y in enr_everp2 enr_everp3 enr_everp4 ever_any ever_aa ever_ba {;
        estout t_`y'_*
	       using tabs2345.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};



*APPENDIX TABLE 6;
foreach y in enr_ever enr_everp2 enr_everp3 ever_any ever_aa ever_ba {;

	*POOR STUDENTS - INTERACT WITH DUMMY FOR HIGH SCHOOL POVERTY SHARE;
	reg `y' treat treat_hs_schl_pov hs_schl_pov block_* 
	female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline 	
		attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if poor==1 & year==2017, vce(cluster bcode);
    estimates store t_`y'_poor;

	*NONPOOR STUDENTS - INTERACT WITH DUMMY FOR HIGH SCHOOL POVERTY SHARE;
	reg `y' treat treat_hs_schl_pov hs_schl_pov block_* 
	female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline 	
		attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if nonpoor==1 & year==2017, vce(cluster bcode);
   	estimates store t_`y'_nonpr;
	
	*HIGH-ACHIEVING STUDENTS - INTERACT WITH DUMMY FOR HIGH ACHIEVING SCHOOL;
	reg `y' treat treat_hs_schl_higs hs_schl_higs block_* 
	female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline 	
		attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if higs==1 & year==2017, vce(cluster bcode);
   	estimates store t_`y'_higs;

	*LOW-ACHIEVING STUDENTS - INTERACT WITH DUMMY FOR HIGH ACHIEVING SCHOOL;
	reg `y' treat treat_hs_schl_higs hs_schl_higs block_* 
	female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline 	
		attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if logs==1 & year==2017, vce(cluster bcode);
   	estimates store t_`y'_logs;
};

estout t_enr_ever_*
       using apptab6.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(N, fmt(0) labels("Observations"))
       keep(treat treat_hs_schl_pov treat_hs_schl_higs);
foreach y in enr_everp2 enr_everp3 ever_any ever_aa ever_ba {;
        estout t_`y'_*
	       using apptab6.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(N, fmt(0) labels("Observations"))
               keep(treat treat_hs_schl_pov treat_hs_schl_higs);
};


*APPENDIX TABLE 3;

estimates clear;
foreach y in enrolled_2018 enrolled_2019 enrolled_2020 enrolled_2021 cont_enr_np1 cont_enr_np2 cont_enr_np3 {;

	foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie {; 

		*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};

estout t_enrolled_2018_*
       using apptab3.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);
foreach y in enrolled_2019 enrolled_2020 enrolled_2021 cont_enr_np1 cont_enr_np2 cont_enr_np3 {;
        estout t_`y'_*
	       using apptab3.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};


*APPENDIX TABLE 4;
estimates clear;

gen hisat2 = sat_composite2>900;
gen losat2 = sat_composite2<=900; 
count if hisat2==1 & year==2017;
count if losat2==1 & year==2017;

gen np_his = hisat==1 & poor==0;
gen np_los = losat==1 & poor==0;

gen higlos = higpa==1 & losat==1;
gen hislog = hisat==1 & logpa==1;

foreach y in enr_ever enr_everp2 enr_everp3 ever_any ever_aa ever_ba {;

	foreach x in all higs logs pr_hie np_hie pr_loe np_loe hisat losat pr_his np_his pr_los np_los {; 

		*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};

estout t_enr_ever_*
       using apptab4.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);
foreach y in enr_everp2 enr_everp3 ever_any ever_aa ever_ba {;
        estout t_`y'_*
	       using apptab4.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};




****APPENDIX TABLE 5;
gen treat_n_gr12_2017 = treat*n_gr12_2017;
gen treat_rural = treat*rural;
gen treat_suburb = treat*suburb;
gen treat_town = treat*town;
gen treat_charter = treat*charter;

count if year==2017 & treat==1 & frac_treated<.5024876;
count if year==2017 & treat==1 & frac_treated>=.5024876 & frac_treated<.6413793;
count if year==2017 & treat==1 & frac_treated>=.6413793 & frac_treated<.8490566;
count if year==2017 & treat==1 & frac_treated>=.8490566;

count if tag==1 & treat==1 & frac_treated<.5024876;
count if tag==1 & treat==1 & frac_treated>=.5024876 & frac_treated<.6413793;
count if tag==1 & treat==1 & frac_treated>=.6413793 & frac_treated<.8490566;
count if tag==1 & treat==1 & frac_treated>=.8490566;

gen high_treat = treat==1 & frac_treated>=.6413793;
gen high_treatq2 = treat==1 & frac_treated>=.5024876 & frac_treated<.6413793;
gen high_treatq3 = treat==1 & frac_treated>=.6413793 & frac_treated<.8490566; 
gen high_treatq4 = treat==1 & frac_treated>=.8490566;

gen not_stand = treat==1 & stand_alone==0;
gen not_english = treat==1 & english_teach==0;

estimates clear;
foreach y in enr_ever ever_aa {;

	foreach x in all higs logs {;
	
	*HAVE DUMMY FOR TREAT AND DUMMY FOR STAND-ALONE COURSE;
	reg `y' treat stand_alone 
	block_* female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score 		
	gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
    estimates store t_`y'_`x'1;
	sum `y' if `x'==1 & year==2017 & treat==0;
	scalar cm = r(mean);
	estadd scalar cm=cm;

	*HAVE DUMMY FOR TREAT AND DUMMY FOR ENGLISH TEACHER;
	reg `y' treat english_teach 
	block_* female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score 		
	gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
    estimates store t_`y'_`x'2;
	sum `y' if `x'==1 & year==2017 & treat==0;
	scalar cm = r(mean);
	estadd scalar cm=cm;

	*HAVE DUMMY FOR TREAT AND CONTINUOUS VARIABLE FOR SHARE ENROLLED;
	reg `y' treat frac_treated 
	block_* female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score 		
	gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
    estimates store t_`y'_`x'3;
	sum `y' if `x'==1 & year==2017 & treat==0;
	scalar cm = r(mean);
	estadd scalar cm=cm;
	
	*THROW THEM ALL IN;
	reg `y' treat stand_alone english_teach frac_treated 
	block_* female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score 		
	gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
    estimates store t_`y'_`x'4;
	sum `y' if `x'==1 & year==2017 & treat==0;
	scalar cm = r(mean);
	estadd scalar cm=cm;
		
	*THROW THEM ALL IN - QUARTILES OF FRATION TREATED;
	reg `y' treat stand_alone english_teach high_treatq2 high_treatq3 high_treatq4 
	block_* female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score 		
	gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
    estimates store t_`y'_`x'5;
	sum `y' if `x'==1 & year==2017 & treat==0;
	scalar cm = r(mean);
	estadd scalar cm=cm;
	};
};

estout t_enr_ever_*
       using apptab5.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat stand_alone english_teach frac_treated high_treatq2 high_treatq3 high_treatq4);
estout t_ever_aa_*
	       using apptab5.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat stand_alone english_teach frac_treated high_treatq2 high_treatq3 high_treatq4);

			   
****Q-VALUES;
foreach group in 1 2 3 4 5 6 {;

	preserve;

	*DEFINE Q-VALUE MATRIX;
	if `group'==1 {; mat define C = J(3, 9, .); local group2 = "enr_ever enr_everp2 enr_everp3"; };
	if `group'==2 {; mat define C = J(3, 9, .); local group2 = "ever_any ever_aa ever_ba"; };
	if `group'==3 {; mat define C = J(3, 9, .); local group2 = "enr_4only enr_2only enr_2and4"; };
	if `group'==4 {; mat define C = J(4, 9, .); local group2 = "enr_safety enr_m_or_r enr_s_only enr_s_and_mr"; };
	if `group'==5 {; mat define C = J(4, 9, .); local group2 = "enr_ft enr_pt_ft enr_pt_only enr_ft_only"; };
	if `group'==6 {; mat define C = J(4, 9, .); local group2 = "enr_ever_stem enr_never_stem enr_gpa_hi enr_gpa_lo"; };
		
	*SET FAMILY TO 1;
	local r=1;
	
	foreach y in `group2' {;

		*SET SUBGROUP Q-VALUE NUMBER TO 1 WITHIN FAMILY (i.e., w/in outcome);
		local s=1;
		
		foreach x in higs logs all poor nonpoor pr_hie np_hie pr_loe np_loe  {;
		
			reg `y' treat block_* 
			female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score 
			gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);			
			
			
			*if "`x'"~="all" {;
			*local t = _b[treat_o]/_se[treat_o];
        		*gen pols_1 = 2*ttail(e(df_r), abs(`t'));
        		mat C[`r', `s']=2*ttail(e(df_r), abs(_b[treat]/_se[treat]));
			local s=`s'+1;
			*};
/*
			sum `y' if e(sample)==1 & treat==0;
                scalar cm = r(mean);
                estadd scalar cm = cm;
                estimates store `y'_`x'_2;
*/
		};
		local r=`r'+1;
	};

	*SPIT OUT Q-VALUE DATASET;
	*preserve;
	*Create vectors of p-values for each regression and calculate qvalues;
	clear;
	svmat C, name(pval);
	save pval.dta, replace;
	do qvalues_code.do;
	svmat Q, name(qval);
	export excel using qvalues_group`group', firstrow(variables) replace;
	restore;
};	



*****GRABBING P-VALUES FROM DIFFERENCES ACROSS SUBGROUPS;
foreach x of var treat block_? block_?? female black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr 
	sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss {;
	gen  `x'_pr = `x' * poor;
};
foreach x of var treat block_? block_?? female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr 
	sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt sat_composite_miss gpa_baseline_miss attendance_rt_miss {;
	gen  `x'_lo = `x' * logs;
};

estimates clear;
gen treat_int=.;

foreach y in enr_ever enr_everp2 enr_everp3 ever_any ever_aa ever_ba  {;

	*POOR INTERACTION - all and by achievement;
	replace treat_int = treat_pr;
	foreach x in all higs logs {; 
		reg `y' treat treat_int block_? block_?? female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite 
		mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss 
			block_?_pr block_??_pr female_pr black_pr hisp_pr oth_race_pr suburb_pr town_pr rural_pr charter_pr n_gr12_2017_pr frac_enr_pr frac_enr_4yr_pr 
			sat_composite_pr mathread_gr8_pr
			has_gr8_score_pr gpa_baseline_pr attendance_rt_pr sat_composite_miss_pr gpa_baseline_miss_pr attendance_rt_miss_pr
			if `x'==1 & year==2017, vce(cluster bcode);
		estimates store t_`y'_pr_`x';
		test treat_int=0;
		scalar pval = r(p);
		estadd scalar pval=pval;
	};
	
	*LOW-ACHIEVING INTERACTION;
	replace treat_int = treat_lo;
	reg `y' treat treat_int block_? block_?? female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss logs
			block_?_lo block_??_lo female_lo black_lo hisp_lo oth_race_lo suburb_lo town_lo rural_lo charter_lo n_gr12_2017_lo frac_enr_lo frac_enr_4yr_lo sat_composite_lo mathread_gr8_lo
			has_gr8_score_lo gpa_baseline_lo attendance_rt_lo sat_composite_miss_lo gpa_baseline_miss_lo attendance_rt_miss_lo
			if year==2017, vce(cluster bcode);
	estimates store t_`y'_lo;
	test treat_int=0;
    scalar pval = r(p);
    estadd scalar pval=pval;
};

*FOR LATER TABLES ONLY DO COMPARISON BY ED WITHIN ACHIEVEMENT GROUPS;
foreach y in enr_4only enr_2only enr_2and4 enr_safety enr_m_or_r enr_s_only enr_s_and_mr enr_ft enr_pt_ft enr_pt_only enr_ft_only enr_ever_stem enr_never_stem enr_gpa_hi enr_gpa_lo {;

	replace treat_int = treat_pr;
	foreach x in higs logs {; 
		reg `y' treat treat_int block_? block_?? female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite 
		mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss 
			block_?_pr block_??_pr female_pr black_pr hisp_pr oth_race_pr suburb_pr town_pr rural_pr charter_pr n_gr12_2017_pr frac_enr_pr frac_enr_4yr_pr 
			sat_composite_pr mathread_gr8_pr
			has_gr8_score_pr gpa_baseline_pr attendance_rt_pr sat_composite_miss_pr gpa_baseline_miss_pr attendance_rt_miss_pr
			if `x'==1 & year==2017, vce(cluster bcode);
		estimates store t_`y'_pr_`x';
		test treat_int=0;
		scalar pval = r(p);
		estadd scalar pval=pval;
	};
};

estout t_enr_ever_* 
       using pvalues.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(pval N, fmt(3 0) labels("P-Value" "Observations"))
       keep(treat treat_int);
foreach y in enr_everp2 enr_everp3 ever_any ever_aa ever_ba enr_4only enr_2only enr_2and4 enr_safety enr_m_or_r enr_s_only enr_s_and_mr enr_ft enr_pt_ft enr_pt_only enr_ft_only enr_ever_stem enr_never_stem enr_gpa_hi enr_gpa_lo {;
        estout t_`y'_*
	       using pvalues.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(pval N, fmt(3 0) labels("P-Value" "Observations"))
               keep(treat treat_int);
};

*Q-VALUES FOR GROUP-DIFFERENCES - first poverty then achievement;
foreach group in 1 2 3 4 5 6 {;

	preserve;

	*DEFINE Q-VALUE MATRIX;
	if `group'==1 {; mat define C = J(3, 9, .); local group2 = "enr_ever enr_everp2 enr_everp3"; };
	if `group'==2 {; mat define C = J(3, 9, .); local group2 = "ever_any ever_aa ever_ba"; };
	if `group'==3 {; mat define C = J(3, 9, .); local group2 = "enr_4only enr_2only enr_2and4"; };
	if `group'==4 {; mat define C = J(4, 9, .); local group2 = "enr_safety enr_m_or_r enr_s_only enr_s_and_mr"; };
	if `group'==5 {; mat define C = J(4, 9, .); local group2 = "enr_ft enr_pt_ft enr_pt_only enr_ft_only"; };
	if `group'==6 {; mat define C = J(4, 9, .); local group2 = "enr_ever_stem enr_never_stem enr_gpa_hi enr_gpa_lo"; };	
	
	*SET FAMILY TO 1;
	local r=1;

	replace treat_int = treat_pr;
	
	foreach y in `group2' {;

		*SET SUBGROUP Q-VALUE NUMBER TO 1 WITHIN FAMILY (i.e., w/in outcome);
		local s=1;

		foreach x in all higs logs  {;

		reg `y' treat treat_int block_? block_?? female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss 
			block_?_pr block_??_pr female_pr black_pr hisp_pr oth_race_pr suburb_pr town_pr rural_pr charter_pr n_gr12_2017_pr frac_enr_pr frac_enr_4yr_pr sat_composite_pr mathread_gr8_pr
			has_gr8_score_pr gpa_baseline_pr attendance_rt_pr sat_composite_miss_pr gpa_baseline_miss_pr attendance_rt_miss_pr
			if `x'==1 & year==2017, vce(cluster bcode);
			
			
		*if "`x'"~="all" {;
		*local t = _b[treat_o]/_se[treat_o];
        	*gen pols_1 = 2*ttail(e(df_r), abs(`t'));
        	mat C[`r', `s']=2*ttail(e(df_r), abs(_b[treat_int]/_se[treat_int]));
		local s=`s'+1;
		*};
/*
		sum `y' if e(sample)==1 & treat==0;
               scalar cm = r(mean);
               estadd scalar cm = cm;
               estimates store `y'_`x'_2;
*/		};
		local r=`r'+1;
	};

	*SPIT OUT Q-VALUE DATASET;
	*preserve;
	*Create vectors of p-values for each regression and calculate qvalues;
	clear;
	svmat C, name(pval);
	save pval.dta, replace;
	do qvalues_code.do;
	svmat Q, name(qval);
	export excel using qvalues_ed_group`group', firstrow(variables) replace;
	restore;
};	

foreach group in 1 2 {;

	preserve;

	*DEFINE Q-VALUE MATRIX;
	if `group'==1 {; mat define C = J(3, 9, .); local group2 = "enr_ever enr_everp2 enr_everp3"; };
	if `group'==2 {; mat define C = J(3, 9, .); local group2 = "ever_any ever_aa ever_ba"; };
	
	*SET FAMILY TO 1;
	local r=1;

	replace treat_int = treat_lo;
	
	foreach y in `group2' {;

		*SET SUBGROUP Q-VALUE NUMBER TO 1 WITHIN FAMILY (i.e., w/in outcome);
		local s=1;

		reg `y' treat treat_int block_? block_?? female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite 
		mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss logs
			block_?_lo block_??_lo female_lo black_lo hisp_lo oth_race_lo suburb_lo town_lo rural_lo charter_lo n_gr12_2017_lo frac_enr_lo frac_enr_4yr_lo 
			sat_composite_lo mathread_gr8_lo
			has_gr8_score_lo gpa_baseline_lo attendance_rt_lo sat_composite_miss_lo gpa_baseline_miss_lo attendance_rt_miss_lo
			if year==2017, vce(cluster bcode);
					
		*if "`x'"~="all" {;
		*local t = _b[treat_o]/_se[treat_o];
        	*gen pols_1 = 2*ttail(e(df_r), abs(`t'));
        	mat C[`r', `s']=2*ttail(e(df_r), abs(_b[treat_int]/_se[treat_int]));
		local s=`s'+1;
		*};
/*
		sum `y' if e(sample)==1 & treat==0;
               scalar cm = r(mean);
               estadd scalar cm = cm;
               estimates store `y'_`x'_2;
*/	
		local r=`r'+1;
	};

	*SPIT OUT Q-VALUE DATASET;
	*preserve;
	*Create vectors of p-values for each regression and calculate qvalues;
	clear;
	svmat C, name(pval);
	save pval.dta, replace;
	do qvalues_code.do;
	svmat Q, name(qval);
	export excel using qvalues_achieve_group`group', firstrow(variables) replace;
	restore;
};	



*TABLE 6;
estimates clear;
foreach y in enr_ever enr_4only enr_2only enr_2and4 enr_4yr enr_2yr first_2yr first_4yr enr_2_4_simal {;

	foreach x in all pr_hie np_hie pr_loe np_loe {; 

		*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x'2;
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};
estout t_*
       using tab6.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);



*TABLE 7;
estimates clear;

foreach y in enr_4yr enr_safety enr_m_or_r enr_s_only enr_s_and_mr {;

	foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie {; 

	*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};
estout t_enr_4yr_all t_enr_4yr_poor t_enr_4yr_nonpoor t_enr_4yr_logs t_enr_4yr_higs t_enr_4yr_pr_loe t_enr_4yr_pr_hie t_enr_4yr_np_loe t_enr_4yr_np_hie
       using tab7.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);

foreach y in  enr_safety enr_m_or_r enr_s_only enr_s_and_mr {;
        estout t_`y'_*
	       using tab7.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};


*TABLE 9;
estimates clear;
foreach y in enr_gpa_hi enr_gpa_lo coll_gpa enr_gpagt2 enr_gpalt2 enr_ever_stem enr_never_stem  {;

	foreach x in all pr_hie np_hie pr_loe np_loe higs logs poor nonpoor {; 

	*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};
estout t_enr_gpa_hi_*
       using tab9.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);

foreach y in enr_gpa_lo coll_gpa enr_gpagt2 enr_gpalt2 /*enr_gpagt3 enr_gpa173 enr_gpalt17*/ enr_ever_stem enr_never_stem /*majority_stem minority_stem*/ {;
        estout t_`y'_*
	       using tab9.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};





*APPENDIX TABLE 10;

gen ever_nsel = enr_ever==1 & inlist(1,enr_sel0,enr_sel2);
gen ever_sel = enr_ever==1 & inlist(1,enr_sel3,enr_sel4,enr_sel5,enr_sel6);
gen only_non = ever_nsel==1 & ever_sel==0;
gen only_sel = ever_nsel==0 & ever_sel==1;
gen both_sel = ever_nsel==1 & ever_sel==1;

foreach y in enr_ever ever_nsel ever_sel only_non only_sel both_sel  {;

	foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie {; 

	*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};	
};
estout t_enr_ever_all t_enr_ever_poor t_enr_ever_nonpoor t_enr_ever_logs t_enr_ever_higs t_enr_ever_pr_loe t_enr_ever_pr_hie t_enr_ever_np_loe t_enr_ever_np_hie
       using apptab10.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);

foreach y in ever_nsel ever_sel only_non only_sel both_sel   {;
        estout t_`y'_*
	       using apptab10.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};



*APPENDIX TABLE 11;
rename enr_ever_instate_pub instate_pub;
gen out_prv_only = enr_ever==1 & instate_pub==0;

foreach y in instate_pub out_prv_only enr_ever {;

	foreach x in all pr_loe pr_hie np_loe np_hie {; 

	*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};	
};
estout t_instate_pub_all t_instate_pub_pr_loe t_instate_pub_pr_hie t_instate_pub_np_loe t_instate_pub_np_hie
       using apptab11.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);

foreach y in out_prv_only enr_ever {;
        estout t_`y'_*
	       using apptab11.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};



*APPENDIX TABLE 14;
gen comfortable=.;
replace comfortable = 1 if comfort_level==4 | comfort_level==5;
replace comfortable = 0 if inlist(comfort_level,1,2,3);
gen v_comfortable=.;
replace v_comfortable = 1 if comfort_level==5;
replace v_comfortable = 0 if inlist(comfort_level,1,2,3,4);

replace completed_fafsa = completed_fafsa2_may if completed_fafsa==0 & completed_fafsa2_may==.;


*ESTIMATE IMPACTS ON APPLICATION BEHAVIOR;
estimates clear;
foreach y in took_survey taught_fafsa comfort_level comfortable v_comfortable completed_fafsa apply_any apply_2yr apply_4yr apply2yr4yr_later apply_um num_apps admitted_4yr enroll_4yr {;

        foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie  {;

                *CONTROL FOR BLOCKS AND CHARACTERISTICS;
                reg `y' treat block_*
                female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
                sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
                estimates store `y'_`x';
                sum `y' if `x'==1 & year==2017 & treat==0;
                scalar cm = r(mean);
                estadd scalar cm=cm;
        };
};
estout took_survey_*
       using apptab14.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);

foreach y in taught_fafsa comfort_level comfortable v_comfortable completed_fafsa apply_any apply_2yr apply_4yr apply2yr4yr_later apply_um num_apps admitted_4yr enroll_4yr {;
        estout `y'_*
               using apptab14.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};



***FIGURES I and II;
estimates clear;
foreach y in enr_ever enr_ever_s2 enr_ever_s3 enr_ever_s4 enr_ever_s5 enr_ever_s6 {;

	foreach x in all poor nonpoor logs higs pr_loe pr_hie np_loe np_hie {; 

	*CONTROL FOR BLOCKS AND CHARACTERISTICS;
		reg `y' treat block_* 
		female poor black hisp oth_race suburb town rural charter n_gr12_2017 frac_enr frac_enr_4yr sat_composite mathread_gr8 has_gr8_score gpa_baseline attendance_rt
    		sat_composite_miss gpa_baseline_miss attendance_rt_miss if `x'==1 & year==2017, vce(cluster bcode);
        	estimates store t_`y'_`x';
		sum `y' if `x'==1 & year==2017 & treat==0;
		scalar cm = r(mean);
		estadd scalar cm=cm;
	};
};
estout t_enr_ever_all t_enr_ever_poor t_enr_ever_nonpoor t_enr_ever_logs t_enr_ever_higs t_enr_ever_pr_loe t_enr_ever_pr_hie t_enr_ever_np_loe t_enr_ever_np_hie
       using figs1and2.txt, replace
       cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
       keep(treat);

foreach y in enr_ever_s2 enr_ever_s3 enr_ever_s4 enr_ever_s5 enr_ever_s6 {;
        estout t_`y'_*
	       using figs1and2.txt, append
               cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(cm N, fmt(3 0) labels("Control Mean" "Observations"))
               keep(treat);
};


log close;

